﻿using UnityEngine;
using System.Collections;
using System.Text;
using System.IO;
using System;
using SevenZip.Compression.LZMA;
using YZL.Compress.UPK;
public static class LZMAUnit{
	public static void PackFolder(string inFile,string outFile,YZL.Compress.Info.ProgressDelegate show,bool autoDele = true){
		var fileinfo = new FileInfo (outFile+".upk");
		var sourceinfo = new DirectoryInfo (inFile);
		if (fileinfo.Exists && autoDele)
			fileinfo.Delete ();
		if (!sourceinfo.Exists) {
			return;
		}
		UPKFolder.PackFolder(inFile,outFile+".upk",show);
		ClearDireFlie (sourceinfo.FullName);
		if(autoDele)
			sourceinfo.Delete ();
	}
	public static void UnPackFolder(string inFile,string outFile,YZL.Compress.Info.ProgressDelegate show){
		var direinfo = new DirectoryInfo (outFile);
		var sourceinfo = new FileInfo (inFile+".upk");
		if (!sourceinfo.Exists)
			return;
		UPKFolder.UnPackFolder(inFile+".upk",outFile,show);
	}
	static void ClearDireFlie(string path){
		var dire = new DirectoryInfo (path);
		var files = dire.GetFiles ();
		for (var i = 0; i < files.Length; i++) {
			File.Delete (files [i].FullName);
		}
	}
}